package com.tueye.web.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;

import com.tueye.entity.Admin;
import com.tueye.utils.TuEyeConstant;
import com.tueye.utils.UtilDateConverter;
/**
 * 
 * @author hxw
 *
 */
public class BaseController {

	private static final Log log = LogFactory.getLog(BaseController.class);
	
	static {
		// 注册UtilDateConverter
		ConvertUtils.register(new UtilDateConverter(), Date.class);

	}

	public ModelAndView Logon(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		log.info("首先判断用户是否登录.......");
		
		Admin currentUser = (Admin) request.getSession().getAttribute(TuEyeConstant.TUEYE_ADMIN);
		ModelAndView mav = new ModelAndView();
		if (currentUser == null) {
			mav.setViewName("/pages/admin/index");
		}else{
			mav.setViewName("/pages/admin/logon");
		}
		
		return mav;
	}

	protected Admin currentUser(HttpServletRequest request) {
		return (Admin) request.getSession().getAttribute(
				TuEyeConstant.TUEYE_ADMIN);
	}
}
